package workflow;

import java.io.File;
import java.io.IOException;

import org.eclipse.emf.mwe2.runtime.workflow.IWorkflowComponent;
import org.eclipse.emf.mwe2.runtime.workflow.IWorkflowContext;

public class Commandline implements IWorkflowComponent {

	private String path;
	private String execute;

	public String getExecute() {
		return execute;
	}

	public String getPath() {
		return path;
	}

	@Override
	public void invoke(final IWorkflowContext context) {
		final Runtime runtime = Runtime.getRuntime();
		try {
			final String currentPath = System.getProperty("user.dir");
			final File workingDirectory = new File(currentPath + "\\"
					+ getPath());
			runtime.exec(getExecute(), null, workingDirectory);
		} catch (final IOException e) {
			e.printStackTrace();
		} catch (final Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void postInvoke() {
		// TODO Auto-generated method stub

	}

	@Override
	public void preInvoke() {
	}

	public void setExecute(final String command) {
		execute = command;
	}

	public void setPath(final String workingDirectory) {
		path = workingDirectory;
	}

}
